<?php
namespace Admin\Controller;

use Think\Controller;

class CommonController extends Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->check_login();
        // dump($_SESSION);
        //dump($_SESSION['user']['token']);

    }

    private function check_login()
    {
     if (isset($_SESSION['user'])){
         $this->assign("user",$_SESSION['user']);
         return;
     }
     if (!isset($_COOKIE['token'])){
         $this->error("你还没有登入",U("User/login"));
     }
           $token=$_COOKIE["token"];
           $User=M("user");
           $User->where("token='$token'")->find();
        if (!$User){
            $this->error("你是非法登入",U("User/login"));
        }
          $_SESSION["user"]=$User;
          $this->assign("user",$User);



    }




}